package org.zhongyin.coolingload;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import org.joda.time.DateTime;
import org.zhongyin.JPA.Entity.PermanentHistoryData;


public class Utility {

	public static Date convertToDate(String str) throws ParseException{
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
				"MM/dd/yy HH:mm");
		Date date = simpleDateFormat.parse(str);
		
		return date;
}
	
	public static Date converToDateHH(Date date) throws ParseException{
		
		DateTime dt = new DateTime(date);
		
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
				"MM/dd/yy HH");
		Date result = simpleDateFormat.parse(dt.toString("MM/dd/yy HH"));
		
		return result;
	}
	
	public static void debug(Object object){
		System.out.println(object);
	}
	
	public static void printArray(double[][] array, int start, int end){
		if(array == null || array.length == 0){
			return;
		}
		
		for(int i = start; i < end; i++){
			System.out.println(Arrays.toString(array[i]));
		}
		
	}
	
	public static String printArray(double[][] array){
		if(array == null || array.length == 0){
			return null;
		}
		String str = "";
		for(int i = 0; i < array.length; i++){
			for(int j = 0; j < array[0].length; j++){
				str += String.format("%.4f ", array[i][j]);
			}
			str += String.format("\n");
		}
		
		return str;
	}
	
	public static void printArraySingleLine(double[][] array){
		if(array == null || array.length == 0){
			return;
		}
		
		for(int i = 0; i < array.length; i++){
			System.out.println(Arrays.toString(array[i]));
		}
		
	}
	
	public static void printArrayList(List<Object[]> list){
		for(Object[] obj: list){
			System.out.println(Arrays.toString(obj));
		}
	}
	
	public static void printArrayListCL(List<PermanentHistoryData> list){
		for(PermanentHistoryData data: list){
			System.out.println(data.getId().getHistDateTime() + ", " + data.getHistValue());
		}
	}
	
	
	public static float getMax(List<Object[]> list){
		if(list == null){
			throw new NullPointerException("List is null");
		}
		
		float max = Float.MIN_VALUE;
		for(int i = 0 ; i < list.size(); i++){
			max = (float)list.get(i)[1] > max ? (float)list.get(i)[1] : max;
		}
		
		return max;
	}
	
	public static float getMin(List<Object[]> list){
		if(list == null){
			throw new NullPointerException("List is null");
		}
		
		float min = Float.MAX_VALUE;
		for(int i = 0 ; i < list.size(); i++){
			min = (float)list.get(i)[1] < min ? (float)list.get(i)[1] : min;
		}
		
		return min;
	}
	
	
	
	
}
